package com.zq.it.dao.impl.exam;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zq.it.dao.exam.TStudentTaskDAO;
import com.zq.it.dao.impl.BaseDao;
import com.zq.it.pojo.exam.TStudentTask;

public class TStudentTaskDAOImpl extends BaseDao<TStudentTask> implements TStudentTaskDAO {

	private static final Logger log = LoggerFactory
			.getLogger(TStudentTaskDAOImpl.class);
	// property constants
	public static final String ISDEMOTE = "isdemote";
	public static final String DEMOTION_MESSAGE = "demotionMessage";
	public static final String MARK = "mark";
	public static final String TASK_URL = "taskUrl";
	public static final String TASK_FILE = "taskFile";
	public static final String START_TIME = "startTime";
	public static final String STATE = "state";
	public static final String EXTEND_FIELD = "extendField";

	@Override
	public void save(TStudentTask transientInstance) {
		log.debug("saving TStudentTask instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	@Override
	public void delete(TStudentTask persistentInstance) {
		log.debug("deleting TStudentTask instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	@Override
	public TStudentTask findById(Long id) {
		log.debug("getting TStudentTask instance with id: " + id);
		try {
			TStudentTask instance = (TStudentTask) getHibernateTemplate()
					.get("com.zq.it.pojo.exam.TStudentTask", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@Override
	public List findByExample(TStudentTask instance) {
		log.debug("finding TStudentTask instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TStudentTask instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TStudentTask as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	@Override
	public List findByIsdemote(Object isdemote) {
		return findByProperty(ISDEMOTE, isdemote);
	}

	@Override
	public List findByDemotionMessage(Object demotionMessage) {
		return findByProperty(DEMOTION_MESSAGE, demotionMessage);
	}

	@Override
	public List findByMark(Object mark) {
		return findByProperty(MARK, mark);
	}

	@Override
	public List findByTaskUrl(Object taskUrl) {
		return findByProperty(TASK_URL, taskUrl);
	}

	@Override
	public List findByTaskFile(Object taskFile) {
		return findByProperty(TASK_FILE, taskFile);
	}

	@Override
	public List findByStartTime(Object startTime) {
		return findByProperty(START_TIME, startTime);
	}

	@Override
	public List findByState(Object state) {
		return findByProperty(STATE, state);
	}

	@Override
	public List findByExtendField(Object extendField) {
		return findByProperty(EXTEND_FIELD, extendField);
	}

	@Override
	public List findAll() {
		log.debug("finding all TStudentTask instances");
		try {
			String queryString = "from TStudentTask";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	@Override
	public void update(TStudentTask instance) {
		log.debug("attaching dirty TStudentTask instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	@Override
	public List findByHql(String hql) {
		log.debug("finding TStudentTask instances by Hql");
		try {
			return getHibernateTemplate().find(hql);
		} catch (RuntimeException re) {
			log.error("find by Hql failed", re);
			throw re;
		}
	}

	@Override
	public void deleteByHql(String hql) {
		super.deleteEntity(hql);
	}

}